import { createRouter } from "../lib/index";
const router = createRouter({
  mode: "hash",
  base: "./",
  routes: [
    {
      name: "home",
      path: "/",
      render: () => {
        console.log("home");
      },
    },
    {
      name: "user",
      path: "/user",
      render: () => {
        console.log("user");
      },
    },
  ],
});
router.addRoute({
  name: "userParams",
  path: "/user-params/id/name",
  render: () => {
    console.log("userParams");
  },
});
router.addRoute({
  name: "defaultHome",
  path: "/default-home",
  redirect: "/",
});
router
  .addRoute({
    name: "deleteHome",
    path: "/delete-home",
    redirect: "/",
  })
  .removeRoute("deleteHome");
const res = router.hasRoute("/delete-home");
console.log(res);
router.beforeEach((from, to, next) => {
  console.log("[beforeEach]", from, to);
  /* Intercept jump */
  if (to && to.path === "/default-home") {
    next("/user");
  } else {
    next();
  }
});
router.afterEach((from, to) => {
  console.log("[afterEach]", from, to);
});
router.forceUpdate();
/* route jump error */
router.routeJumpErrorFeedBack((err) => console.error(err));
console.log(router);
